package com.example.chenjun.myapplication.mvp;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

/**
 * @author chenj
 * @date 2018/2/27 0027
 */

public class MVPFragment<P extends BasePresenter, M extends BaseModel> extends Fragment {

    protected P mPresenter;
    protected M mModel;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = getPresenterInstance();
        mModel = getModelInstance();
        IView view = null;
        if (this instanceof IView){
            view = (IView) this;
        }
        if (mPresenter != null) {
            mPresenter.setViewModel(view, mModel);
        }
    }

    private P getPresenterInstance() {
        return TypeUtil.getType(0, this);
    }

    private M getModelInstance() {
        return TypeUtil.getType(1, this);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}
